/* --------------------------------- ved.js --------------------------------- */
VED.instances = {};
VED.document = new VED.dom.document( document );

VED.add = function( editor ) {
   VED.instances[ editor.name ] = editor;

   editor.on( 'focus', function() {
      if ( VED.currentInstance != editor ) {
         VED.currentInstance = editor;
         VED.fire( 'currentInstance' );
      }
   });

   editor.on( 'blur', function() {
      if ( VED.currentInstance == editor ) {
         VED.currentInstance = null;
         VED.fire( 'currentInstance' );
      }
   });

   VED.fire( 'instance', null, editor );
};


VED.remove = function( editor ) {
   delete VED.instances[ editor.name ];
};


(function() {
   var tpls = {};

   VED.addTemplate = function( name, source ) {
      var tpl = tpls[ name ];
      if ( tpl )
         return tpl;

      // Make it possible to customize the template through event.
      var params = { name: name, source: source };
      VED.fire( 'template', params );

      return ( tpls[ name ] = new VED.template( params.source ) );
   };

   VED.getTemplate = function( name ) {
      return tpls[ name ];
   };
})();


(function() {
   var styles = [];

   VED.addCss = function( css ) {
      styles.push( css );
   };

   VED.getCss = function() {
      return styles.join( '\n' );
   };
})();

// Perform global clean up to free as much memory as possible
// when there are no instances left
VED.on( 'instanceDestroyed', function() {
   if ( VED.tools.isEmpty( this.instances ) )
      VED.fire( 'reset' );
});

// Load the bootstrap script.
// VED.loader.load( '_bootstrap' ); // %REMOVE_LINE%

// Tri-state constants.
VED.TRISTATE_ON = 1;
VED.TRISTATE_OFF = 2;
VED.TRISTATE_DISABLED = 0;







